﻿using Collections2;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestTwoWayDictionary
{
    public enum States { AL, AK, OH}
    

    class Program
    {
        public static string[] statenames = new string[] { "Alabama", "Alaska", "Ohio" };
        public static string[] statenames2 = new string[] { "Alabama", "Alaska", "Ohio", "Texas" };
        public static string[] stateabbr = new string[] { "AL", "AK", "OH" };
        public static States[] thestates;

        protected static TwoWayDictionary<States, string> states;
        protected static TwoWayDictionary<string> states2;

        static void Main(string[] args)
        {
            thestates = (States[])Enum.GetValues(typeof(States));
            states = new TwoWayDictionary<States,string>(thestates,statenames);
            states2 = new TwoWayDictionary<string>(stateabbr, statenames);
            
            

            Console.Write("Input the state name:");
            string strstate = Console.ReadLine();

            while (true)
            {
                if (strstate != "Q")
                {
                    try
                    {
                        Console.WriteLine(states[strstate.Trim()]);
                    }

                    catch (TwoWayDictException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    Console.Write("Input the state name:");
                    strstate = Console.ReadLine();
                }
                else
                {
                    break;
                }
            }

            Console.Write("Input the state abbreviation:");
            strstate = Console.ReadLine();

            while (true)
            {
                if (strstate != "Q")
                {
                    try
                    {
                        Console.WriteLine(states[(States)Enum.Parse(typeof(States), strstate)]);
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    catch (TwoWayDictException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    Console.Write("Input the state abbreviation:");
                    strstate = Console.ReadLine();
                }
                else
                {
                    break;
                }
            }

            Console.Write("Input the state name:");
            strstate = Console.ReadLine();

            while (true)
            {
                if (strstate != "Q")
                {
                    try
                    {
                        Console.WriteLine(states2[strstate]);
                    }
                    catch (TwoWayDictException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    Console.Write("Input the state name:");
                    strstate = Console.ReadLine();
                }
                else
                {
                    break;
                }
            }

            Console.Write("Input the state abbreviation:");
            strstate = Console.ReadLine();

            while (true)
            {
                if (strstate != "Q")
                {
                    try
                    {
                        Console.WriteLine(states2[strstate]);
                    }
                    catch (TwoWayDictException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    Console.Write("Input the state abbreviation:");
                    strstate = Console.ReadLine();
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine(states.Contains(States.OH));
            Console.WriteLine(states.Contains("Alabama"));   
            Console.WriteLine(states.Contains("Vermont"));
            Console.WriteLine("Count = " + states.Count);
            states.Remove(States.AK);
            Console.WriteLine("Count = " + states.Count);
            Console.ReadLine();

            try
            {
                states.Remove("Colorado");
            }

            catch (TwoWayDictException ex)
            {
                Console.WriteLine(ex.Message);
                // Console.WriteLine("The key = Colorado was not found!");
            }

            try
            {
                states = new TwoWayDictionary<States, string>(thestates, statenames2);

            }

            catch (TwoWayDictException ex)
            {
                Console.WriteLine(ex.Message);
                // Console.WriteLine("The key = Colorado was not found!");
            }

            states[States.AL] = "Alabama2";
            Console.WriteLine(states[States.AL]);
            states2["AL"] = "Alabama3";
            Console.WriteLine(states2["AL"]);
            states2["Ohio"] = "OH2";
            Console.WriteLine(states2["Ohio"]);

            Console.ReadLine();
        }
    }
}
